package com.live.stamp.base.validation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.container.core.common.BusinessException;

/**
 * 数组验证处理器
 */
public class ArrayHandle extends ParamHandler {
    private static final Logger logger = LoggerFactory.getLogger(ArrayHandle.class);

    @Override
    protected ValidationEnum getParamHandleType() {
        return ValidationEnum.ARRAY;
    }

    @Override
    protected void echo(String paramName, Object param) {
        Object[] c = (Object[]) param;
        if(c == null){
            logger.error("ArrayHandle class -> param:{} is null!", paramName);
            throw new BusinessException(String.format("参数%s为空", paramName));
        }
        if(c.length == 0){
            logger.error("ArrayHandle class -> param:{} length is zero!", paramName);
            throw new BusinessException(String.format("数组%s长度为0", paramName));
        }
    }
}
